<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>开心E城</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <!-- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> -->
        <link rel="stylesheet" href="/static/admin/css/font.css">
        <link rel="stylesheet" href="/static/admin/css/xadmin.css">
        <script src="/static/admin/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/admin/js/xadmin.js"></script>
        <link rel="stylesheet" href="/static/admin/lib/bootstrap/bootstrap.min.css">   
        <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
        <style>
        	.layui-form-label {
        		width: 100px;
        	}
        </style>
    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form">
					<div class="layui-form-item">
						<label for="nickname" class="layui-form-label">
							<span class="x-red">*</span>位置
						</label>
						<div class="layui-input-block">
							<div class="layui-input-inline">
				        	<select name="ad_position_id" lay-filter="" lay-verify="required">
					           	<option value="">请选择</option>
					           	{volist name='postitonList' id='vo'}
					           	<option {if isset($data.ad_position_id)}{if $data.ad_position_id eq $vo.id} selected="selected" {/if}{/if} value="{$vo.id}">{$vo.name}</option>
					           	{/volist}
				          	</select>
				          </div>
				        </div>
					</div>
					<div class="layui-form-item">
					    <label class="layui-form-label">
					    	<span class="x-red">*</span>名称
						</label>
					    <div class="layui-input-block">
					    	<div class="layui-input-inline">
					      		<input type="text" name="name" lay-verify="required" placeholder="输入名称" autocomplete="off" class="layui-input" value="{$data.name|default=''}" required="required">
					    	</div>
						</div>
				  	</div>
				  	<div class="layui-form-item">
					    <label class="layui-form-label">
					    	<span class="x-red"></span>链接	
						</label>
					    <div class="layui-input-block">
					    	<div class="layui-input-inline">
					      		<input type="text" name="link" lay-verify="" placeholder="输入链接" autocomplete="off" class="layui-input" value="{$data.link|default=''}">
					    	</div>
						</div>
				  	</div>
				  	<label class="layui-form-label">
				  		结束时间
				  	</label>
				  	<div class="layui-input-block">
					    <div class="layui-input-inline">
					        <input type="text" name="end_time" id="date1" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input" value="{$data.end_time|default=''}">
					    </div>
					</div>
				  	<div class="layui-form-item">
						<label class="layui-form-label">
					    	<span class="x-red">*</span>图片	
						</label>
						<div class="layui-input-block">
							<button type="button" class="layui-btn" id="uploadImg">
								<i class="layui-icon">&#xe67c;</i>上传图片
							</button>
						</div>
					</div>
					{if isset($data.image_url)}
					<div class="layui-form-item">
						<div class="layui-input-block">
							<img src="{$data.image_url|default=''}" style="height: 200px;">
						</div>
					</div>
					{/if}
				  	<div class="layui-form-item">
					    <label class="layui-form-label">
					    	<span class="x-red"></span>内容描述	
						</label>
					    <div class="layui-input-block">
					      	<textarea placeholder="请输入内容" class="layui-textarea" name="content">{$data.content|default=''}</textarea>
						</div>
				  	</div>
					<div class="layui-form-item">
						{if isset($data.id)}
						<input type="hidden" name="id" value="{$data.id}">
						{/if}
						<label for="" class="layui-form-label"></label>
						<button  class="layui-btn layui-btn-danger" lay-filter="save" lay-submit="save" id='save'>保存</button>
					</div>
              </form>
            </div>
        </div>
        <script>
        	layui.use(['form', 'layer', 'upload', 'laydate'],
            function() {
                $ = layui.jquery;
                var form = layui.form;
                var layer = layui.layer;
                var upload = layui.upload;
                var laydate = layui.laydate;

 				//日期
				laydate.render({
				    elem: '#date1'
				});

                //自定义验证规则
                form.verify({
                   
                });

                //上传图片
				var uploadInst = upload.render({
					elem: '#uploadImg', //绑定元素
					url: '{:url("backstage/ad/uploadImg")}', //上传接口
					done: function(res){
						$('#avatar').val(res.data);
						layer.msg(res.msg);
					},
					error: function(){
				  		//请求异常回调
					}
				});

                //监听提交
                form.on('submit(save)',function(data) {
                    $.ajax({
                    	url:'{:url("backstage/ad/form")}',
                    	type:'post',
                    	dataType:'json',
                    	data:data.field,
                    	success: res => {
                    		if (res.code == 1) {
                    			layer.alert(res.msg, {
			                        icon: 6
			                    },
			                    function() {
			                        //关闭当前frame
			                        xadmin.close();
			                        // 可以对父窗口进行刷新 
			                        xadmin.father_reload();
			                    });
                    		} else {
                    			layer.alert(res.msg, {
			                        icon: 5
			                    });
                    		}
                    	},
                    	error: e => {}
                    });
                    return false;
                });

            });
        </script>
        <script>
        	var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
    </body>
</html>
